package wyh.mapper;

import org.apache.ibatis.annotations.*;
import wyh.pojo.Patient;

import java.util.List;

/**
 * -- 创建 patientinfo 患者表
 * CREATE TABLE patientinfo
 * (
 *     patientId     INT PRIMARY KEY AUTO_INCREMENT, -- 患者唯一标识
 *     name          VARCHAR(50),                    -- 患者姓名
 *     age           INT,                            -- 陪诊人员年龄
 *     sex           VARCHAR(10),                    -- 性别
 *     contactNumber VARCHAR(20)                     -- 联系电话
 * );
 */

@Mapper
public interface PatientMapper {

    // 根据姓名模糊查询患者信息
    @Select("SELECT * FROM patientinfo WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<Patient> MappergetByNameLike(String name);

    @Select("select * from patientinfo")
    List<Patient> MappergetAll();

    @Select("select * from patientinfo where patientId=#{patientId}")
    Patient MappergetById(int patientId);

    @Delete("delete from patientinfo where patientId=#{patientId}")
    int MapperdeleteUserById(int patientId);

    @Update("update patientinfo set name=#{name} , age=#{age}, sex=#{sex}, contactNumber=#{contactNumber}  where patientId=#{patientId}")
    int MapperupdateUserById(Patient patient);

    @Insert("insert into patientinfo value (null,#{name},#{age},#{sex},#{contactNumber})")
    int MapperaddUser(Patient patient);

        @Insert("insert into patientinfo (name, age, sex, contactNumber) values (#{name}, #{age}, #{sex}, #{contactNumber})")
        @Options(useGeneratedKeys = true, keyProperty = "patientId")
        int MapperaddUser2(Patient patient);


}
